package com.oa.system;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 代码生成
 * 生成 dao entity mapper文件
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class MybatisGenerator {
    @Test
    public void generator() throws Exception {
        List<String> warnings = new ArrayList<String>();
        File configFile = new File(
                "C:/Users/Administrator/Desktop/OA/jlh/src/main/resources/generatorConfig.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(true);
        MyBatisGenerator myBatisGenerator =
                new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);

    }
}